package cn.yunhe.action;

import cn.yunhe.entity.User;
import cn.yunhe.services.UserLoginService;
import cn.yunhe.util.BaseUtil;
import lombok.Data;

import java.io.IOException;
import java.io.PrintWriter;

@Data
public class UserLoginAction extends BaseUtil {
    private String username;
    private String password;

    public String login() throws IOException {
        UserLoginService userLoginService=new UserLoginService();
        User user=userLoginService.login(username,password);
        if (user!=null){
            getMapSession().put("user",user);
            return SUCCESS;
        }else{
            getMapRequest().put("msg","用户名或密码错误");
            return ERROR;
        }
    }

    public String addUser() throws IOException {
        PrintWriter out = getResponse().getWriter();
        out.print("<h1>正在添加用户</h1>");
        return null;
    }
}
